package com.alm.token.ui.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alm.token.ConStant;
import com.alm.token.GlideApp;
import com.alm.token.MyApp;
import com.alm.token.R;
import com.alm.token.base.BaseActivity;
import com.alm.token.base.BaseAdapter;
import com.alm.token.common.RefreshLoadMoreManager;
import com.alm.token.ui.data.bean.ChannelTypeData;
import com.alm.token.ui.data.bean.DrawIndexData;
import com.alm.token.ui.data.bean.LeHuoBaoListData;
import com.alm.token.ui.data.bean.RegisterData;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.ui.view.LeHuoBaoView;
import com.alm.token.utils.ActionBarHelper;
import com.alm.token.utils.CommonUtil;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.widget.CustomTabLayout;
import com.alm.token.widget.FullyLinearLayoutManager;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CurrencyDetailActivity extends BaseActivity implements LeHuoBaoView<Object> {
    @BindView(R.id.leftItem)
    ImageView leftItem;
    @BindView(R.id.centerItem)
    TextView centerItem;
    @BindView(R.id.rightItem)
    TextView rightItem;
    @BindView(R.id.tab)
    CustomTabLayout tab;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.tv_transferqrCode)
    LinearLayout tvTransferqrCode;
    @BindView(R.id.tv_transferout)
    LinearLayout tvTransferout;
    @BindView(R.id.tv_keyongmoneyshow)
    TextView tvKeyongmoneyshow;
    @BindView(R.id.img_currency_cion)
    ImageView imgCurrencyIcon;
    @BindView(R.id.tv_keyongmoney)
    TextView tvKeyongmoney;
    @BindView(R.id.tv_lockMoney)
    TextView tvLockMoney;
    @BindView(R.id.tv_clickreload)
    TextView tvClickreload;
    @BindView(R.id.nodatashow_body)
    RelativeLayout nodatashowBody;
    @BindView(R.id.scroll_view)
    NestedScrollView scrollView;
    @BindView(R.id.tv_adressshow)
    TextView tvAdressshow;
    @BindView(R.id.tv_copyadress)
    TextView tvCopyadress;
    @BindView(R.id.tv_adressshow2)
    TextView tvAdressshow2;
    @BindView(R.id.tv_copyadress2)
    TextView tvCopyadress2;
    @BindView(R.id.rly_xrpbody)
    RelativeLayout rlyXrpbody;
    @BindView(R.id.tv_adressshow2msg)
    TextView tvAdressshow2msg;
    @BindView(R.id.ly_btnbody)
    LinearLayout lyBtnbody;

    private RefreshLoadMoreManager<LeHuoBaoListData.DataBeanX.ListBean.DataBean> manager;
    private List<ChannelTypeData.DataBean.ChannelListBean> channelListBeans = new ArrayList<>();//name : 锁仓
    private List<ChannelTypeData.DataBean.MoneyTypeListBean> moneyTypeListBeans = new ArrayList<>();//name : ETH
    private List<ChannelTypeData.DataBean.IncomeTypeListBean> incomeTypeListBeans = new ArrayList<>();//name : 收入
    private List<LeHuoBaoListData.DataBeanX.ListBean.DataBean> dataBeanList = new ArrayList<>();
    private LeHuoBaoListData.DataBeanX.WalletBean walletBean;

    private int channelListBeansType, moneyTypeListBeansType, incomeTypeListBeansType;

    private String orderId, limit, page, channelType, moneyType = "1", incomeType;
    private String tabName1, tabName3;
    private ChannelTypeData.DataBean channelTypeDataBean;
    private String bizhongName = "";
    private String rechargeAddress;
    private String walletAddress = "", walletAddressTag = "";
    public static final int INTENTTYPE_KUA = 1;
    private int intentType = 0;

    @Override
    protected MyPreenter initPreenter() {
        return new MyPreenter(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_currency_detail;
    }

    @Override
    protected void initVariables() {
        UserWalletData.DataBean.WalletsBean item = (UserWalletData.DataBean.WalletsBean) getIntent().getSerializableExtra("WalletsBean");
        intentType = getIntent().getIntExtra("intentType", 0);

        lyBtnbody.setVisibility(intentType == INTENTTYPE_KUA ? View.GONE : View.VISIBLE);

        new ActionBarHelper(this).setTitle(item != null && !item.getName().isEmpty() ? item.getName() : getString(R.string.currency_hint_title1)).setRightIcon(R.drawable.icon_trounout_top1)
                .setRightListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(TransformActivity.class);
                    }
                });

        GlideApp.with(this)
                .load(item.getLogo()).listener(new RequestListener<Drawable>() {
            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                return false;
            }

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
//                if (EmptyUtils.isNotEmpty(resource)) {
//                    CommonUtil.changeSVGColor(CurrencyDetailActivity.this, imgCurrencyIcon, resource, R.color.black);
//                    return true;
//                }
                return false;
            }
        })
                .error(R.drawable.icon_arctic)
                .into(imgCurrencyIcon);

        channelTypeDataBean = MyApp.getChannelTypeDataBean();
        bizhongName = item != null && !item.getName().isEmpty() ? item.getName() : getString(R.string.currency_hint_title1);
        if (item != null) {
            if (channelTypeDataBean != null && channelTypeDataBean.getMoneyTypeList() != null
                    && channelTypeDataBean.getMoneyTypeList().size() != 0) {
                moneyType = String.valueOf(item.getId());
                tvTransferqrCode.setBackground(getResources().getDrawable(R.drawable.grey_btn_bg1));
                tvTransferqrCode.setTag(99);
                tvTransferout.setBackground(getResources().getDrawable(R.drawable.grey_btn_bg1));
                tvTransferout.setTag(99);
            } else {
//                moneyType = name.indexOf("ETH") != -1 ? "1" : "2";
            }
        }
    }

    @Override
    protected void initViews() {

        ChannelTypeData.DataBean dataBean = MyApp.getChannelTypeDataBean();
        if (dataBean != null) {

            ChannelTypeData.DataBean.ChannelListBean bean = new ChannelTypeData.DataBean.ChannelListBean();
            bean.setName(getString(R.string.profile_hint_item11));
            bean.setType(0);
            channelListBeans.add(0, bean);
            channelListBeans.addAll(dataBean.getChannelList());


            ChannelTypeData.DataBean.MoneyTypeListBean bean1 = new ChannelTypeData.DataBean.MoneyTypeListBean();
            bean1.setName(getString(R.string.profile_hint_item11));
            bean1.setType(0);
            moneyTypeListBeans.add(0, bean1);
            moneyTypeListBeans.addAll(dataBean.getMoneyTypeList());

            ChannelTypeData.DataBean.IncomeTypeListBean bean2 = new ChannelTypeData.DataBean.IncomeTypeListBean();
            bean2.setName(getString(R.string.profile_hint_item11));
            bean2.setType(0);
            incomeTypeListBeans.add(0, bean2);
            incomeTypeListBeans.addAll(dataBean.getIncomeTypeList());
        }

        orderId = "";
        limit = "100";
        page = "1";
        channelType = channelListBeans != null && channelListBeans.size() != 0 ? channelListBeans.get(0).getType() + "" : "";
//        moneyType = "";
        incomeType = incomeTypeListBeans != null && incomeTypeListBeans.size() != 0 ? incomeTypeListBeans.get(0).getType() + "" : "";

        String[] tabNames = {channelListBeans != null && channelListBeans.size() != 0 ? channelListBeans.get(0).getName() : getString(R.string.profile_hint_item11),
                incomeTypeListBeans != null && incomeTypeListBeans.size() != 0 ? incomeTypeListBeans.get(0).getName() + "" : getString(R.string.profile_hint_item11)};
        tabName1 = tabNames[0];
        tabName3 = tabNames[1];
        tab.setItemLayout(R.layout.item_income_expend_tab);
        tab.setTabNames(tabNames);
        tab.setTabCall(new CustomTabLayout.TabCall() {
            @Override
            public void item(int position, FrameLayout frameLayout) {
                if (position == 0) {
                    showPopupMenu1(frameLayout);
                } else if (position == 1)
                    showPopupMenu3(frameLayout);


            }
        });
        tab.notifyChange();

        initManager();
        recyclerView.setVisibility(View.GONE);
        nodatashowBody.setVisibility(View.VISIBLE);
        scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_MOVE:
                        break;

                    case MotionEvent.ACTION_DOWN:
                        break;

                    case MotionEvent.ACTION_UP:
                        //当文本的measureheight 等于scroll滚动的长度+scroll的height
                        if (scrollView.getChildAt(0).getMeasuredHeight() <= scrollView.getScrollY() + scrollView.getHeight()) {
                            showWaitDialog();
                            preenter.getLeHuoBaoListData(orderId, limit, page, channelType, moneyType, incomeType);
                        } else {

                        }
                        break;

                }
                return false;
            }
        });
    }

    private void initManager() {
        IncomeAdapter adapter = new IncomeAdapter(this);
        manager = new RefreshLoadMoreManager.Builder(this)
                .setAdapter(adapter)
                .setRecyclerView(recyclerView)
                .setLayoutManager(new FullyLinearLayoutManager(this))
                .setOnListItemClickListener(new RefreshLoadMoreManager.OnListItemClickListener() {
                    @Override
                    public void onListItemClick(BaseAdapter.BaseItem item, int position) {
//                        if (dataBeansGuanbi != null && dataBeansGuanbi.size() > position) {
//                            Intent intent = new Intent(QuantitativeOrderCloseListActivity.this, QuantitativeOrderDetailActivity.class);
//                            intent.putExtra("databean", dataBeansGuanbi.get(position));
//                            startActivityForResult(intent, ActivityForResultCode);
//                        }
//                        startActivity(QuantitativeOrderDetailActivity.class);
                    }
                })
//                .setSwipeRefreshLayout(swipeRefreshLayout)
//                .setOnRefreshListener(new RefreshLoadMoreManager.OnRefreshListener() {
//                    @Override
//                    public void onRefresh() {
////                        showToast("onRefresh");
//                        swipeRefreshLayout.setRefreshing(false);
//                        preenter.getLeHuoBaoListData(orderId, limit, page, channelType, moneyType, incomeType);
//                    }
//                })

                .build();
//         .setOpenLoadMore(true)
//                .setOnLoadMoreListener(new RefreshLoadMoreManager.OnLoadMoreListener() {
//
//                    @Override
//                    public void onLoadMore() {
//                        manager.getAdapter().loadMoreEnd(true);
//                        manager.getAdapter().loadMoreFail();
////                        if(dataBeans.size()!=9){
////                            dataBeans.clear();
////                        }
//                        showWaitDialog();
////                        loadMoreData(ticker);
//                        preenter.getLeHuoBaoListData(orderId, limit, page, channelType, moneyType, incomeType);
//
//                    }
//                })
        recyclerView.setNestedScrollingEnabled(false);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (EmptyUtils.isNotEmpty(dataBeanList) && dataBeanList.size() > position) {
                    Intent intent = new Intent(CurrencyDetailActivity.this, LogDetailActivity.class);
                    intent.putExtra("LogDetailActivity_type", LogDetailActivity.BILL_TYPE);
                    intent.putExtra("LogDetailActivity_id", dataBeanList.get(position).getId());
                    startActivity(intent);
                }
            }
        });
    }

    public void mathRequest() {
        limit = "100";
        page = "1";

        preenter.getLeHuoBaoListData(orderId, limit, page, channelType, moneyType, incomeType);
    }

    @Override
    protected void loadData() {
        /**
         * @param orderId     量化订单id
         * @param limit       条数 100
         * @param page        页数  1
         * @param channelType 收益类型，全部传null值
         * @param moneyType   金额类型
         * @param incomeType  收入支出类型
         */

        orderId = "";
        limit = "100";
        page = "1";
        channelType = "";

        incomeType = "";

        preenter.getLeHuoBaoListData(orderId, limit, page, channelType, moneyType, incomeType);
    }

    @Override
    public void onClick(View v) {

    }

    @OnClick({R.id.tv_transferqrCode, R.id.tv_transferout, R.id.tv_copyadress, R.id.tv_copyadress2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_copyadress:
                if (walletAddress.isEmpty()) {
                    showToast(getString(R.string.network_loading_hint1));
                    break;
                }
                copyWalletAddress();
                break;
            case R.id.tv_copyadress2:
                if (walletAddressTag.isEmpty()) {
                    showToast(getString(R.string.network_loading_hint1));
                    break;
                }
                copyWalletAddress1();
                break;
            case R.id.tv_transferqrCode:
                if (tvTransferqrCode.getTag() != null) {
                    showToast(getString(R.string.currency_hint1_warn));
                    break;
                }
                Intent intent1 = new Intent(this, TransferQrCodeActivity_new.class);
                intent1.putExtra("bizhongType", Integer.parseInt(moneyType));
                intent1.putExtra("bizhongName", bizhongName);
                startActivity(intent1);
                break;
            case R.id.tv_transferout:
                if (EmptyUtils.isNotEmpty(tvTransferqrCode.getTag()) && (int) tvTransferqrCode.getTag() == 99) {
                    showToast(getString(R.string.currency_hint1_warn));
                    break;
                }

                ShowProgress();
                preenter.getDrawIndexData(moneyType);

//                startActivity(TurnOutActivity.class);
                break;
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    private boolean isfull = false;
    private List<LeHuoBaoListData.DataBeanX.ListBean.DataBean> dataBeanListold = new ArrayList<>();

    @Override
    public void getLeHuoBaoListData(LeHuoBaoListData leHuoBaoListData) {
        if (leHuoBaoListData.getStatus() == 0 && leHuoBaoListData.getData() != null) {
            walletBean = leHuoBaoListData.getData().getWallet();
            if (walletBean != null) {
                tvKeyongmoneyshow.setText(getString(R.string.currency_hint_usable));
                tvKeyongmoney.setText(CommonUtil.saveToPoint4WithNo(walletBean.getActiveMoney()));
                tvLockMoney.setText(CommonUtil.saveToPoint4WithNo(walletBean.getFrozenMoney()));//冻结额度
            }

            rechargeAddress = leHuoBaoListData.getData().getRechargeAddress();

            if (EmptyUtils.isNotEmpty(rechargeAddress)) {
                tvTransferout.setBackground(getResources().getDrawable(R.drawable.shape_btnbgd_solkie));
                tvTransferout.setTag(null);
                tvTransferqrCode.setBackground(getResources().getDrawable(R.drawable.shape_btnbgd_solkie));
                tvTransferqrCode.setTag(null);

//                tvAdressshow2msg.setVisibility(View.VISIBLE);
                tvAdressshow2msg.setVisibility(View.GONE);
                tvAdressshow.setVisibility(View.VISIBLE);
                tvCopyadress.setVisibility(View.VISIBLE);
                if (!TextUtils.isEmpty(bizhongName) && (bizhongName.equalsIgnoreCase("XRP") || bizhongName.equalsIgnoreCase("EOS")
                        || bizhongName.equalsIgnoreCase("HEOS") || bizhongName.equalsIgnoreCase("HXRP"))) {
                    rlyXrpbody.setVisibility(View.VISIBLE);
                    String[] adress = rechargeAddress.split("_");
                    walletAddress = adress[0];
                    walletAddressTag = adress[1];
                    tvAdressshow.setText(walletAddress);
                    tvAdressshow2.setText("Tag：" + walletAddressTag);
                    tvAdressshow2msg.setText(getString(R.string.wallet_hint_xrpmsg, bizhongName));
                } else {
                    rlyXrpbody.setVisibility(View.GONE);
                    walletAddressTag = "";
                    walletAddress = rechargeAddress;
                    tvAdressshow.setText(rechargeAddress);
                    tvAdressshow2.setText("Tag：" + walletAddressTag);
                    tvAdressshow2msg.setText(getString(R.string.wallet_hint_bishow2msg, EmptyUtils.isNotEmpty(bizhongName) ? bizhongName : ""));
                }
            } else {
                rlyXrpbody.setVisibility(View.GONE);
                tvAdressshow2msg.setVisibility(View.GONE);
                tvAdressshow.setVisibility(View.GONE);
                tvCopyadress.setVisibility(View.GONE);
            }
            if (leHuoBaoListData.getData().getList() != null && leHuoBaoListData.getData().getList().getData() != null) {


                if (Integer.valueOf(page) == 1) {
                    dataBeanList.clear();
                } else if (!isfull && dataBeanList.size() > (Integer.valueOf(page) - 1) * 100) {
                    dataBeanList.removeAll(dataBeanListold);
                }
//            dataBeanList.clear();
                if (leHuoBaoListData.getData().getList().getData().size() == 100) {
                    isfull = true;
                    page = String.valueOf(Integer.valueOf(page) + 1);
                } else {
                    isfull = false;
                }

                dataBeanListold = leHuoBaoListData.getData().getList().getData();


                for (int i = 0; i < dataBeanListold.size(); i++) {
                    dataBeanListold.get(i).setLayoutId(BillActivity.IncomeAdapter.LAYOUT_ID);
                }
                dataBeanList.addAll(dataBeanListold);
                manager.setData(dataBeanList);
            }

        } else
            showToast(leHuoBaoListData.getMsg());

        if (dataBeanList.size() == 0) {
            recyclerView.setVisibility(View.GONE);
            nodatashowBody.setVisibility(View.VISIBLE);
        } else {
            nodatashowBody.setVisibility(View.GONE);
            recyclerView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void getLeHuoTopUpsData(RegisterData leHuoTopUpsData) {

    }

    @Override
    public void getData(Object o) {
        if (o instanceof DrawIndexData && o != null) {
            DrawIndexData.DataBean dataBean = ((DrawIndexData) o).getData();
            MyApp.setDrawIndexDataBean(dataBean);

            if (MyApp.getDrawIndexDataBean() != null) {

                Intent intent = new Intent(this, TurnOutActivity.class);
                intent.putExtra("bizhongtype", moneyType);
                startActivity(intent);
            }
        }
    }

    @Override
    public void jumpToLoginAct(int staue) {
        if (staue == 3) {
//            showToast(getString(R.string.common_relogin));
//            Intent intent = new Intent();
//            intent.setAction(ConStant.EXIT_APP);
//            sendBroadcast(intent);
//            startActivity(BlockWalletLoginActivity.class);
//            finish();
        } else if (staue == 4) {
//            showToast(getString(R.string.paypasw_hint_setpaypsw));
//            Intent intent = new Intent(this,PayPwdActivity.class);
//            intent.putExtra("PayPwdActivityType",PayPwdActivity.PAYPSW_SET);
//            startActivity(intent);
//            finish();
            showToSetPaypswDialog();
        } else if (staue == 666) {
            showToUpdata();
        }
    }

    @Override
    public void onError(String error) {

        showToast(getString(R.string.common_loaderrritry));
    }

    @Override
    public void ShowProgress() {
        showWaitDialog();
    }

    @Override
    public void hideProgress() {
        hideWaitDialog();
    }

    @OnClick(R.id.tv_clickreload)
    public void onViewClicked() {
        mathRequest();
//        preenter.getLeHuoBaoListData(orderId, limit, page, channelType, moneyType, incomeType);
    }

    public class IncomeAdapter extends BaseAdapter<LeHuoBaoListData.DataBeanX.ListBean.DataBean> {

        public static final int LAYOUT_ID = R.layout.item_income_expend;

        public IncomeAdapter(@NonNull Context context) {
            super(context);
        }

        @Override
        protected void convert(BaseViewHolder helper, LeHuoBaoListData.DataBeanX.ListBean.DataBean dataBean, int itemType) {
            if (dataBean == null)
                return;

            helper.setText(R.id.tv_channelType, dataBean.getChannelTypeStr() + "");
            helper.setText(R.id.tv_createTime, CommonUtil.getDateTimeFromMillisecond(dataBean.getUpdateTime() != 0 ? dataBean.getUpdateTime() : dataBean.getCreateTime()));
            double money = dataBean.getMoney();
            if (money < 0) {
                helper.setTextColor(R.id.tv_money, getResources().getColor(R.color.lehuobao_zhichu));
                helper.setImageDrawable(R.id.icon, getResources().getDrawable(R.drawable.icom_outdown));
                helper.setText(R.id.tv_money, CommonUtil.saveToPoint4WithNo(money));
            } else {
                helper.setTextColor(R.id.tv_money, getResources().getColor(R.color.colorgreen1));

                helper.setImageDrawable(R.id.icon, getResources().getDrawable(R.drawable.icom_getup));
                helper.setText(R.id.tv_money, "+" + CommonUtil.saveToPoint4WithNo(money));
            }
        }

    }

    public void showPopupMenu1(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(this, view);
        //加载menu布局
        Menu menu = popupMenu.getMenu();
        for (ChannelTypeData.DataBean.ChannelListBean channelListBean : channelListBeans) {
            if (!tabName1.equalsIgnoreCase(channelListBean.getName())) {
                menu.add(channelListBean.getName());
            }
        }
        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu, menu);
//        popupMenu.set

        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {

                for (int i = 0; i < channelListBeans.size(); i++) {
                    if (item.getTitle().toString().equalsIgnoreCase(channelListBeans.get(i).getName())) {
                        if (channelListBeansType != channelListBeans.get(i).getType()) {
                            channelListBeansType = channelListBeans.get(i).getType();//0 全部  1 2 3
                            channelType = channelListBeansType + "";
                            tabName1 = item.getTitle().toString();
                            tab.setTabTitle(0, item.getTitle().toString());
                            mathRequest();
                        }
                        break;
                    }
                }
                return true;
            }
        });
        popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
            @Override
            public void onDismiss(PopupMenu menu) {
                // 控件消失时的事件
            }
        });


        popupMenu.show();
    }

    ////    channelListBeansType,moneyTypeListBeansType,incomeTypeListBeansType
    public void showPopupMenu3(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(this, view);
        //加载menu布局
        Menu menu = popupMenu.getMenu();
        for (ChannelTypeData.DataBean.IncomeTypeListBean incomeTypeListBean : incomeTypeListBeans) {
            if (!tabName3.equalsIgnoreCase(incomeTypeListBean.getName())) {
                menu.add(incomeTypeListBean.getName());
            }
        }
        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu, menu);


        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {

                for (int i = 0; i < incomeTypeListBeans.size(); i++) {
                    if (item.getTitle().toString().equalsIgnoreCase(incomeTypeListBeans.get(i).getName())) {

                        if (incomeTypeListBeansType != incomeTypeListBeans.get(i).getType()) {
                            incomeTypeListBeansType = incomeTypeListBeans.get(i).getType();//0 全部  1 2 3
                            incomeType = incomeTypeListBeansType + "";
                            tabName3 = item.getTitle().toString();
                            tab.setTabTitle(1, item.getTitle().toString());
                            mathRequest();
                        }
                        break;
                    }
                }
                return true;
            }
        });
        popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
            @Override
            public void onDismiss(PopupMenu menu) {
                // 控件消失时的事件
            }
        });
        popupMenu.show();
    }

    private void copyWalletAddress() {
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        // 将文本内容放到系统剪贴板里。
        if (cm != null) {
            // 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("Label", walletAddress);
            // 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
        }
        showToast(getString(R.string.profile_hint_item14));
//        tvCopyadress.setText(getString(R.string.profile_hint_item14));
    }

    private void copyWalletAddress1() {
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        // 将文本内容放到系统剪贴板里。
        if (cm != null) {
            // 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("Label", walletAddressTag);
            // 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
        }
        showToast(getString(R.string.profile_hint_item14));
//        tvCopyadress2.setText(getString(R.string.profile_hint_item14));
    }
}
